package com.cssw.fyzb.core.dao.user;

import com.cssw.fyzb.core.model.dodb.*;
import com.cssw.fyzb.core.util.*;
import com.ydn.dbframe.kit.StrKit;
import com.ydn.dbframe.plugin.activerecord.Db;
import com.ydn.dbframe.plugin.activerecord.Page;
import com.ydn.dbframe.plugin.activerecord.Record;
import com.ydn.dbframe.plugin.activerecord.parse.SqlParse;
import org.springframework.stereotype.Repository;

import java.math.BigInteger;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author Feng Chen
 */
@Repository
public class UserDaoImpl implements UserDao {

    @Override
    public Long save(Long supUserId, String mobile, String loginPwd, String tradePwd, Integer floor, String avatar, String nickName) {
        User user = new User();
        if (supUserId != null) {
            user.setSupUserId(supUserId);
        }
        user.setMobile(mobile);
        user.setNickName(nickName);
        user.setLoginPwd(AesUtil.encode(loginPwd));
        if (StringUtil.isNotEmpty(tradePwd)) {
            user.setTradePwd(AesUtil.encode(tradePwd));
        }
        user.setStatus(User.STATUS_NORMAL);
        user.setCreateTime(new Date());
        user.setAvatar(avatar);
        user.save();

        //新增短视频用户
        CmfUser cmfUser = new CmfUser();
        cmfUser.setId(new BigInteger(user.getUserId().toString()));
        cmfUser.setAvatar(avatar);
        cmfUser.setUserType(2);
        cmfUser.setUserNicename(nickName);
        cmfUser.setAvatarThumb(avatar);
        cmfUser.setUserLogin(mobile);
        cmfUser.save();
        return user.getUserId();
    }

    @Override
    public Long save(Long supUserId, String mobile, String loginPwd, String tradePwd, Integer floor, String userName, String nickName, String province, String city, String sex, String avatar) {
        User user = new User();
        if (supUserId != null) {
            user.setSupUserId(supUserId);
        }
        user.setMobile(mobile);
        user.setLoginPwd(AesUtil.encode(loginPwd));
        user.setTradePwd(AesUtil.encode(tradePwd));

        user.setStatus(User.STATUS_NORMAL);
        user.setCreateTime(new Date());
        user.setUserName(userName);
        user.setNickName(nickName);
        user.setProvince(province);
        user.setCity(city);
        user.setSex(sex);
        user.setAvatar(avatar);
        user.save();

        //新增短视频用户
        CmfUser cmfUser = new CmfUser();
        cmfUser.setId(new BigInteger(user.getUserId().toString()));
        cmfUser.setAvatar(avatar);
        cmfUser.setUserType(2);
        cmfUser.setUserNicename(nickName);
        cmfUser.setAvatarThumb(avatar);
        cmfUser.setUserLogin(mobile);
        cmfUser.save();
        return user.getUserId();
    }

    @Override
    public void update(Long userId, String userame, String idCard, String province, String city, String district) {
        User user = User.dao.findById(userId);
        if (user != null) {
            user.setUserName(userame);
            user.setIdCard(idCard);
            user.setProvince(province);
            user.setCity(city);
            user.setDistrict(district);
            user.update();
        }
    }

    @Override
    public void updateUserName(Long userId, String userName) {
        User user = User.dao.findById(userId);
        if (user != null && userName != null) {
            user.setUserName(userName);
            user.update();
        }
    }

    @Override
    public void updateMobile(Long userId, String mobile) {
        User user = User.dao.findById(userId);
        if (user != null && mobile != null) {
            user.setMobile(mobile);
            user.update();
        }
    }

    @Override
    public void updateProvince(Long userId, String province) {
        User user = User.dao.findById(userId);
        if (user != null && province != null) {
            user.setProvince(province);
            user.update();
        }
    }

    @Override
    public void updateCity(Long userId, String city) {
        User user = User.dao.findById(userId);
        if (user != null && city != null) {
            user.setCity(city);
            user.update();
        }
    }

    @Override
    public void updateFaceAuth(User user, String status) {
        if (user != null) {
            user.setFaceAuth(status);
            user.update();

            //修改短视频用户信息
            CmfUser cmfUser = new CmfUser();
            cmfUser.setId(new BigInteger(user.getUserId().toString()));
            cmfUser.setIsauth(true);
            cmfUser.update();
        }
    }

    @Override
    public User getByMobile(String mobile, String pwd) {
        Map<String, Object> param = new HashMap<>();
        param.put("mobile", mobile);
        param.put("pwd", AesUtil.encode(pwd));
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL("SELECT * FROM t_user");
        sqlParse.addSQL(" WHERE mobile =:mobile");
        sqlParse.addSQL(" AND login_pwd=:pwd");
        return User.dao.findFirst(sqlParse);
    }

    @Override
    public User getByTradePwd(Long userId, String tradePwd) {
        Map<String, Object> param = new HashMap<>();
        param.put("userId", userId);
        param.put("tradePwd", AesUtil.encode(tradePwd));
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL("SELECT * FROM t_user");
        sqlParse.addSQL(" WHERE user_id =:userId");
        sqlParse.addSQL(" AND trade_pwd=:tradePwd");
        return User.dao.findFirst(sqlParse);
    }

    @Override
    public User getByMobile(String mobile) {
        Map<String, Object> param = new HashMap<>();
        param.put("mobile", mobile);
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL("SELECT * FROM t_user");
        sqlParse.addSQL(" WHERE mobile=:mobile");
        return User.dao.findFirst(sqlParse);
    }

    @Override
    public User getById(Long userId) {
        return User.dao.findById(userId);
    }

    @Override
    public void updateUserLevel(Long userId, Integer level) {
        User user = User.dao.findById(userId);
        if (user != null) {
            user.setUserLevel(level);
            user.update();
        }
    }

    @Override
    public void updateTeamLevel(Long userId, Integer level) {
        User user = new User();
        user.setUserId(userId);
        user.setTeamLevel(level);
        user.update();
    }

    @Override
    public void updateImsi(Long userId, String imsi) {
        User user = User.dao.findById(userId);
        if (user != null) {
            user.setImsi(imsi);
            user.update();
        }
    }

    @Override
    public void updateAvatar(Long userId, String avatar) {
        User user = User.dao.findById(userId);
        if (user != null) {
            user.setAvatar(avatar);
            user.update();

            //修改短视频用户信息
            CmfUser cmfUser = new CmfUser();
            cmfUser.setId(new BigInteger(user.getUserId().toString()));
            cmfUser.setAvatar(avatar);
            cmfUser.setAvatarThumb(avatar);
            cmfUser.update();
        }
    }

    @Override
    public void updateNickName(Long userId, String nickname) {
        User user = User.dao.findById(userId);
        if (user != null) {
            user.setNickName(nickname);
            user.update();

            //修改短视频用户信息
            CmfUser cmfUser = new CmfUser();
            cmfUser.setId(new BigInteger(user.getUserId().toString()));
            cmfUser.setUserNicename(nickname);
            cmfUser.update();
        }
    }

    @Override
    public void updateSex(Long userId, String sex) {
        User user = User.dao.findById(userId);
        if (user != null) {
            user.setSex(sex);
            user.update();

            //性别；0：保密，1：男；2：女
            int cmfSex = 0;
            if (User.SEX_M.equals(sex)) {
                cmfSex = 1;
            } else if (User.SEX_W.equals(sex)) {
                cmfSex = 2;
            }

            //修改短视频用户信息
            CmfUser cmfUser = new CmfUser();
            cmfUser.setId(new BigInteger(user.getUserId().toString()));
            cmfUser.setSex(cmfSex);
            cmfUser.update();
        }
    }

    @Override
    public void updateBirthday(Long userId, String birthday) {
        User user = User.dao.findById(userId);
        if (user != null) {
            user.setBirthday(DateUtil.parseMbl(birthday));
            user.update();
        }
    }

    @Override
    public void updateSign(Long userId, String sign) {
        User user = User.dao.findById(userId);
        if (user != null) {
            user.setSign(sign);
            user.update();

            //修改短视频用户信息
            CmfUser cmfUser = new CmfUser();
            cmfUser.setId(new BigInteger(user.getUserId().toString()));
            cmfUser.setSignature(sign);
            cmfUser.update();
        }
    }

    @Override
    public void updateLoginPwd(Long userId, String loginPwd) {
        User user = new User();
        user.setUserId(userId);
        user.setLoginPwd(AesUtil.encode(loginPwd));
        user.update();
    }

    @Override
    public void updateTradePwd(Long userId, String tradePwd) {
        User user = new User();
        user.setUserId(userId);
        user.setTradePwd(AesUtil.encode(tradePwd));
        user.update();
    }

    @Override
    public int getUserRatioById(Long userId) {
        StringBuilder sql = new StringBuilder();
        sql.append(" select t2.ratio from t_user t1, d_user_level t2  ")
                .append(" where t1.user_id = ? ")
                .append(" and t2.level_code = t1.user_level ");
        return Db.queryInt(sql.toString(), userId);
    }

    @Override
    public long getProvinceUserCount(String province) {
        String sql = "select count(user_id) total from t_user where province=? ";
        return Db.queryLong(sql, province);
    }

    @Override
    public long getCityUserCount(String city) {
        String sql = "select count(user_id) total from t_user where city=? ";
        return Db.queryLong(sql, city);
    }

    @Override
    public Integer countUserBySupUserId(Long supUserId) {
        String sql = "select count(1) total from t_user where sup_user_id=? ";
        return Db.queryInt(sql, supUserId);
    }

    @Override
    public Integer countVDirectSuberBySupId(Long supUserId) {
        String sql = "select count(1) total from t_user t1, t_user_ext t2 where sup_user_id=? and t2.user_id = t1.user_id and t2.valid_user = 1";
        return Db.queryInt(sql, supUserId);
    }

    @Override
    public long getDistrictUserCount(String district) {
        String sql = "select count(user_id) total from t_user where district=? ";
        return Db.queryLong(sql, district);
    }

    @Override
    public Page<Record> listUserDirectVitality(Long userId, int page, int limit) {
        Map param = new HashMap();
        param.put("supUserId", userId);
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL(" select t1.*,t2.active_num from t_user t1   ");
        sqlParse.addSQL("  left join t_user_ext t2 on t2.user_id = t1.user_id ");
        sqlParse.addSQL(" where t1.sup_user_id = :supUserId order by t1.user_id ");
        return Db.paginate(page, limit, sqlParse);
    }

    @Override
    public Page<User> listUserDirectFriendByCond(Map param, int page, int limit) {
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL(" select * from t_user ");
        sqlParse.addSQL(" where 1=1 ");
        sqlParse.addSQL(" and sup_user_id = :supUserId ");
        sqlParse.addLikeSQL(" and ( mobile like :keyword ");
        sqlParse.addLikeSQL("  or nick_name like :keyword )");
        sqlParse.addSQL(" order by user_id ");
        return User.dao.paginate(page, limit, sqlParse);
    }

    @Override
    public String getUserLevelById(Long userId) {
        String sql = " select level_code from t_user t1\n" +
                "left join d_user_level t2 on t1.user_level = t2.level_id\n" +
                "where t1.user_id = ? ";

        return Db.queryStr(sql, userId);
    }

    @Override
    public User getByImsi(String imsi) {
        String sql = "select * from t_user where imsi = ?";

        return User.dao.findFirst(sql, imsi);
    }

    @Override
    public User getByTradeImsi(String tradeImsi) {
        String sql = "select * from t_user where trade_imsi = ?";

        return User.dao.findFirst(sql, tradeImsi);
    }

    @Override
    public Long saveFaceAuthLog(Long userId, String mobileNo, String userName, String idCard,
                                String imageUrl, String status, String msg, String code, int costTime) {
        UserFaceLog log = new UserFaceLog();
        log.setUserId(userId);
        log.setMobileNo(mobileNo);
        log.setUserName(userName);
        log.setIdCard(idCard);
        log.setImageUrl(imageUrl);
        log.setStatus(status);
        log.setResponseMsg(msg);
        log.setResponseCode(code);
        log.setCreateTime(new Date());
        log.setCostTime(costTime);
        log.setDayTime(TimeUtil.getTimeYYMMDD(new Date()));
        log.save();

        return log.getLogId();
    }

    @Override
    public Long saveUserAuthLog(Long userId, String userName, String idCard, String status, String msg, String code, int costTime) {
        UserAuthLog log = new UserAuthLog();
        log.setUserId(userId);
        log.setUserName(userName);
        log.setIdCard(idCard);
        log.setStatus(status);
        log.setResponseMsg(msg);
        log.setResponseCode(code);
        log.setCreateTime(new Date());
        log.setCostTime(costTime);
        log.setDayTime(TimeUtil.getTimeYYMMDD(new Date()));
        log.save();

        return log.getLogId();
    }

    @Override
    public UserFaceLastFail queryFaceLastFail(Long userId) {
        return UserFaceLastFail.dao.findById(userId);
    }

    @Override
    public void saveFaceLastFail(Long userId, Integer respCode, String respMsg) {
        UserFaceLastFail faceLastFail = queryFaceLastFail(userId);

        if (StrKit.notBlank(respMsg) && respMsg.length() > 400) {
            respMsg = respMsg.substring(0, 400);
        }

        if (null == faceLastFail) {
            faceLastFail = new UserFaceLastFail();
            faceLastFail.setUserId(userId);
            faceLastFail.setRespCode(respCode);
            faceLastFail.setRespMsg(respMsg);
            faceLastFail.setCreateTime(new Date());
            faceLastFail.save();
        } else {
            faceLastFail.setRespCode(respCode);
            faceLastFail.setRespMsg(respMsg);
            faceLastFail.setCreateTime(new Date());
            faceLastFail.update();
        }
    }

    @Override
    public List<User> listByIdCard(String idCard) {
        String sql = "select * from t_user where id_card = ? limit 10";
        return User.dao.find(sql, idCard);
    }

    @Override
    public Long saveTecentAuthFaceSend(
            String orderNo, String nonce, Long userId,
            String status, String respCode, String respMsg,
            String userName, String idNo

    ) {
        TecentAuthFaceSend log = new TecentAuthFaceSend();
        log.setOrderNo(orderNo);
        log.setNonce(nonce);
        log.setUserId(userId);
        log.setStatus(status);
        log.setRespCode(respCode);
        log.setRespMsg(respMsg);
        log.setUserName(userName);
        log.setIdNo(idNo);

        log.save();
        return log.getLogId();
    }

    @Override
    public Long saveTecentAuthFaceQuery(
            String orderNo, String nonce, Long userId, String status,
            String respCode, String respMsg,
            String userName, String idNo
    ) {
        TecentAuthFaceQuery log = new TecentAuthFaceQuery();
        log.setOrderNo(orderNo);
        log.setNonce(nonce);
        log.setUserId(userId);
        log.setStatus(status);
        log.setRespCode(respCode);
        log.setRespMsg(respMsg);
        log.setUserName(userName);
        log.setIdNo(idNo);

        log.save();
        return log.getLogId();
    }

    @Override
    public TecentAuthFaceSend getTecentAuthFaceSend(Long userId, String orderNo) {
        String sql = " select * from t_tecent_auth_face_send where user_id = ? and order_no = ? and status = ? ";

        return TecentAuthFaceSend.dao.findFirst(sql, userId, orderNo, TecentAuthFaceSend.STATUS_SUCC);
    }

    @Override
    public Page<User> listUserChildByCond(Map param, int page, int limit) {
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL(" select * from t_user t1 ");
        sqlParse.addSQL(" inner join t_user_tree t2 on t1.user_id = t2.user_id ");
        sqlParse.addSQL(" where t2.sup_user_id  = :userId ");
        sqlParse.addSQL(" and t1.is_real = :isReal ");
        sqlParse.addLikeSQL(" and ( t1.mobile like :keyword ");
        sqlParse.addLikeSQL("  or t1.user_name like :keyword )");
        sqlParse.addSQL(" order by t1.user_id ");
        return User.dao.paginate(page, limit, sqlParse);
    }

    @Override
    public Page<User> pageUserFans(Map param, int page, int limit) {
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL(" select * from t_user t1 ");
        sqlParse.addSQL(" inner join t_user_rel t2 on t1.user_id = t2.user_id ");
        sqlParse.addSQL(" where t2.rel_user_id  = :userId ");
        sqlParse.addSQL(" order by t1.user_id ");
        return User.dao.paginate(page, limit, sqlParse);
    }

    @Override
    public Page<User> pageUserFollow(Map param, int page, int limit) {
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL(" select * from t_user t1 ");
        sqlParse.addSQL(" inner join t_user_rel t2 on t1.user_id = t2.rel_user_id ");
        sqlParse.addSQL(" where t2.user_id  = :userId ");
        sqlParse.addSQL(" order by t1.user_id ");
        return User.dao.paginate(page, limit, sqlParse);
    }

    @Override
    public Page<User> pageUserFriend(Map param, int page, int limit) {
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL(" select * from t_user t1 ");
        sqlParse.addSQL(" inner join t_user_rel t2 on t1.user_id = t2.rel_user_id ");
        sqlParse.addSQL(" where t2.user_id  = :userId and t2.rel_type = 1 ");
        sqlParse.addSQL(" order by t1.user_id ");
        return User.dao.paginate(page, limit, sqlParse);
    }

    @Override
    public void saveAuthInfo(Long userId, String userName, String province, String city, String district, String idCard) {
        User user = User.dao.findById(userId);
        user.setUserName(userName);
        user.setCity(city);
        user.setProvince(province);
        user.setDistrict(district);
        user.setIdCard(idCard);
        user.update();
    }

    @Override
    public Page<User> searchUser(Map<String, Object> param, Integer pageNumber, Integer pageSize) {
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL("select * from t_user where 1=1");
        sqlParse.addSQL(" and user_id=:key");
        return User.dao.paginate(pageNumber, pageSize, sqlParse);
    }

    @Override
    public User getAuthUserById(String idCard) {
        String sql = " select * from t_user where id_card = ? and face_auth = ? ";
        return User.dao.findFirst(sql, idCard, User.FACE_AUTH_YES);
    }

    @Override
    public void saveCmfToken(Long userId, String token) {
        CmfUserToken userToken = new CmfUserToken();
        userToken.setUserId(userId);
        userToken.setToken(token);
        userToken.setCreateTime(System.currentTimeMillis() / 1000);
        userToken.setDeviceType("android");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            userToken.setExpireTime((sdf.parse("2099-12-31 23:59:59").getTime()) / 1000);
            CmfUser cmfUser = new CmfUser();
            cmfUser.setId(new BigInteger(userToken.getUserId().toString()));
            cmfUser.setLastLoginTime(Long.valueOf(System.currentTimeMillis()/1000).intValue());
            cmfUser.update();
        } catch (ParseException e) {
            e.printStackTrace();
            userToken.setExpireTime(System.currentTimeMillis() + (30 * 24 * 60 * 60 * 1000));
        }
        userToken.save();
    }

    @Override
    public CmfUserToken getCmfTokenByUserId(Long userId) {
        String sql = "select * from cmf_user_token where user_id = ?";
        return CmfUserToken.dao.findFirst(sql, userId);
    }

    @Override
    public void updateCmfToken(CmfUserToken userToken) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            userToken.setExpireTime((sdf.parse("2099-12-31 23:59:59").getTime()) / 1000);
            CmfUser cmfUser = new CmfUser();
            cmfUser.setId(new BigInteger(userToken.getUserId().toString()));
            cmfUser.setLastLoginTime(Long.valueOf(System.currentTimeMillis()/1000).intValue());
            cmfUser.update();
        } catch (ParseException e) {
            userToken.setExpireTime(4102415999L);
        }
        userToken.update();
    }

    public void saveCmfUserAuth(String userName, String msg, Boolean status, Integer userId) {
        CmfUserAuth cmfUserAuth = new CmfUserAuth();
        cmfUserAuth.setRealName(userName);
        cmfUserAuth.setReason(msg);
        cmfUserAuth.setStatus(status);
        Long addtime = System.currentTimeMillis() % 1000;
        cmfUserAuth.setAddtime(addtime.intValue());
        cmfUserAuth.setUid(userId.longValue());
        cmfUserAuth.save();
    }

    @Override
    public void updateCmfUser(CmfUser cmfUser) {
        CmfUser c = CmfUser.dao.findById(cmfUser.getId());
        c.setArea(cmfUser.getArea());
        c.setProvince(cmfUser.getProvince());
        c.setCity(cmfUser.getCity());
        c.update();
    }

    @Override
    public Integer countUser() {
        StringBuilder str = new StringBuilder();
        str.append("select count(1) from t_user ");
        return Db.queryInt(str.toString());
    }

    @Override
    public User getIdCard(String idCard) {
        StringBuilder str = new StringBuilder();
        str.append("select * from t_user where id_card=?");
        return User.dao.findFirst(str.toString(), idCard);
    }

    @Override
    public Page<User> list(Map param, int page, int limit) {
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL(" select * from t_user ");
        sqlParse.addSQL(" where 1=1 ");
        return User.dao.paginate(page, limit, sqlParse);
    }


    @Override
    public void updateStatus(Long userId, String status) {
        User user = User.dao.findById(userId);
        if (user != null) {
            user.setStatus(status);
            user.update();

            //修改短视频用户信息
            CmfUser cmfUser = new CmfUser();
            cmfUser.setId(new BigInteger(user.getUserId().toString()));
            cmfUser.setUserStatus(User.STATUS_NORMAL.equals(status) ? 1 : 0);
            cmfUser.update();
        }
    }

    @Override
    public Page<User> page(int pageNum, int pageSize) {
        SqlParse sqlParse = new SqlParse(new HashMap());
        sqlParse.addSQL(" select * from t_user t1 ");
        sqlParse.addSQL(" order by t1.user_id ");
        return User.dao.paginate(pageNum, pageSize, sqlParse);
    }

    @Override
    public Page<User> pageVip(int pageNum, int pageSize) {
        SqlParse sqlParse = new SqlParse(new HashMap());
        sqlParse.addSQL(" select * from t_user t1 where vip = '1' ");
        sqlParse.addSQL(" order by t1.user_id ");
        return User.dao.paginate(pageNum, pageSize, sqlParse);
    }

    @Override
    public void updateAuthPay(Long userId) {
        User user = User.dao.findById(userId);
        user.setAuthPay(User.AUTH_PAY_YES);
        user.update();
    }

    @Override
    public void saveAuthRecord(Long userId, String userName, String idCard, String province, String city, String district) {
        UserAuthRecord userAuthRecord = new UserAuthRecord();
        userAuthRecord.setUserId(userId);
        userAuthRecord.setUserName(userName);
        userAuthRecord.setIdCard(idCard);
        userAuthRecord.setProvince(province);
        userAuthRecord.setCity(city);
        userAuthRecord.setDistrict(district);
        userAuthRecord.save();
    }

    @Override
    public void updateFace(Long userId, String face) {
        User user = new User();
        user.setUserId(userId);
        user.setFace(face);
        user.update();
    }

    @Override
    public void updateVip(Long userId, String vip, String userOpenVipTimeLong) {
        User user = new User();
        user.setUserId(userId);
        String isVip = user.getVip();
        user.setVip(vip);
        user.update();
        if(vip.equals("1")){
            if(isVip.equals("1")){
                Date vipEndTime = user.getVipEndTime();
                if(vipEndTime==null){
                    vipEndTime = new Date();
                }
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Calendar cal = Calendar.getInstance();
                cal.setTime(vipEndTime);
                cal.add(Calendar.MONTH, Integer.parseInt(userOpenVipTimeLong));
                user.setVipEndTime(cal.getTime());
            }else{
                user.setVipStartTime(new Date());
                Date vipEndTime = new Date();
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Calendar cal = Calendar.getInstance();
                cal.setTime(vipEndTime);
                cal.add(Calendar.MONTH, Integer.parseInt(userOpenVipTimeLong));
                user.setVipEndTime(cal.getTime());
            }
        }

        //修改短视频用户信息
        CmfUser cmfUser = new CmfUser();
        cmfUser.setId(new BigInteger(user.getUserId().toString()));
        cmfUser.setVip(vip);
        cmfUser.update();
    }

    @Override
    public void updatePendantUrl(Long userId, String pendantUrl) {
        User user = new User();
        user.setUserId(userId);
        user.setPendantUrl(pendantUrl);
        user.update();

        //修改短视频用户信息
        CmfUser cmfUser = new CmfUser();
        cmfUser.setId(new BigInteger(user.getUserId().toString()));
        cmfUser.setPendantUrl(pendantUrl);
        cmfUser.update();
    }

    @Override
    public void updateFyNo(Long userId, Long fyNo, Integer fyNoNum) {
        User user = new User();
        user.setUserId(userId);
        user.setFyNo(fyNo);
        user.setFyNoNum(fyNoNum);
        user.update();

        //修改短视频用户信息
        CmfUser cmfUser = new CmfUser();
        cmfUser.setId(new BigInteger(user.getUserId().toString()));
        cmfUser.setFyNo(fyNo);
        cmfUser.update();
    }

    @Override
    public User getByFyNo(Long fyNo) {
       String sql = "select * from t_user where fy_no = ?";
       return User.dao.findFirst(sql, fyNo);
    }
}
